I created a function that takes a list as an argument, and returns the highest and lowest number in the list so, it should work like this <pre class='prettyprint lang-py'> >>> min_max([124, 34534, 34544]) <<< [124, 34544]
def min_max(lst): for x in list(lst): profit_lst = [min(x), max(x)] return profit_lst
But I'm getting TypeError: 'int' object is not iterable Can anyone help with this?
You must be logged in to post. Please login or register an account.
First, if you are already using a list as the argument for the
min_max()
function you dont need to use
list()
inside the function, second if you iterate over the elements of the list there is no maximum or minimum since you are only reviewing 1 number at a time, you should erase that for loop and just keep the
return [max(lst), min(lst)]
-maybejose 7 years ago
You must be logged in to post. Please login or register an account.
Thank you for the reply, It worked.
-PyLORD 7 years ago
Last edited 7 years ago
You must be logged in to post. Please login or register an account.